home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / devel / eiffel / eiffel_p.z / eiffel_p / ep / Test / TestMEY.e
Encoding:
Text File  |  1992-12-09  |  1.2 KB  |  70 lines

  1. -- From B.Meyer, Eiffel - The Language
  2.  
  3. class ACCOUNT creation
  4.  
  5.   make
  6.  
  7. feature
  8. -- feature comment
  9.  
  10.   balance: INTEGER;
  11.   owner: PERSON;
  12.   minimum_balance: INTEGER is 1000;
  13.  
  14.   open(who: PERSON) is
  15.       -- Assign the account to owner who
  16.     do
  17.       owner := who
  18.     end -- open
  19.     
  20.  
  21.   deposit(sum: INTEGER) is
  22.       -- Deposit sum into account
  23.     require
  24.       sum >= 0
  25.     do
  26.       add(sum)
  27.     ensure
  28.       balance = old balance + sum
  29.     end; -- deposit
  30.   
  31.   withdraw(sum: INTEGER) is
  32.       -- Withdraw sum from the account
  33.     require
  34.       sum >= 0;
  35.       sum <= balance - minimum_balance
  36.     do
  37.       add(-sum)
  38.     ensure
  39.       balance = old balance - sum
  40.     end; -- withdraw
  41.  
  42.   may_withdraw(sum: INTEGER): BOOLEAN is
  43.       -- Is there enough to withdraw sum?
  44.     do
  45.       Result := (balance >= sum + minimum_balance)
  46.     end -- may_withdraw
  47.  
  48. feature { NONE }
  49.   
  50.   add(sum: INTEGER) is
  51.       -- Add sum to the balance
  52.       -- (Secret procedure)
  53.     do
  54.       balance := balance + sum
  55.     end; -- add
  56.  
  57.   make(initial: INTEGER) is
  58.       -- Initialize account with balance initial.
  59.     require
  60.       initial >= minimum_balance
  61.     do
  62.       balance := initial
  63.     end -- make
  64.  
  65. invariant
  66.   balance >= minimum_balance
  67. end -- class ACCOUNT
  68.  
  69.   
  70.